from datetime import datetime
from typing import TypedDict,  List, Union, Optional, Tuple

from db.models import Review


class ProductEvaluationData(TypedDict):
    """ Оценки продукта за определенный день """

    date: datetime
    name: str
    evaluation: Union[float, str]
    number_of_points_of_sale: Union[int, str]


class CumulativeProductEvaluationData(TypedDict):
    """ Накопительная оценка продукта за определенную дату """

    list_of_product_evaluation: List[ProductEvaluationData]
    grand_total: float


class AverageProductEvaluationData(TypedDict):
    """ Средняя оценка продукта за определенную дату """

    list_of_product_evaluation: List[ProductEvaluationData]
    grand_total: float


class PointsOfSaleStatisticsData(TypedDict):
    """ Точки продаж """

    list_of_product_evaluation: List[ProductEvaluationData]
    grand_total: int
    total_number_of_points_of_sale: int


class ProductWithBadReviewsData(TypedDict):
    """ Продукты с 'плохими' отзывами """

    product_name: str
    date: datetime
    list_of_reviews: List[Review]


class StatisticsData(TypedDict):
    """ Данные статистики """

    average_product_evaluations: List[AverageProductEvaluationData]
    cumulative_product_evaluations: List[CumulativeProductEvaluationData]
    points_of_sale: List[PointsOfSaleStatisticsData]
    product_with_bad_reviews: List[ProductWithBadReviewsData]


class TableData(TypedDict):
    """ Данные таблицы """

    header: List[Union[str, int]]
    body: List[List[Union[str, int]]]
    footer: Optional[List[Union[str, int]]]


class StatisticsFilesData(TypedDict):
    """ Файлы статистики """

    average_evalution: Tuple[str, str, str]
    number_of_points_of_sale: Tuple[str, str, str]
    cumilative_evaluation: Tuple[str, str, str]
    table_of_bad_reviews: Tuple[str, str, str]


class EmailForMallingData(TypedDict):
    """ Электронные почты для рассылки """

    senders_email_name: str
    senders_email_password: str
    list_of_emails_for_malling: List[str]


start_table_of_products_html = """
    <!DOCTYPE html>
    <html lang="ru">
      <head>
        <meta charset="UTF-8">
        <title>Плохие отзывы продуктов</title>
      </head>
      <body>
        <table>
          <tr>
            <th>Товар</th>
            <th>Дата</th>
            <th>Отзыв</th>
          <tr>
"""

end_table_of_products_html = """
    <style>
        table {
            border: 1px solid black;
            border-collapse: collapse;
        }
        td {
            border: 1px solid black;
            padding: .5em;
        }
    </style>
    </body>
    </html>
"""
